;Turn on the echo-check mode
!echoCheck true
;-----------------------------------------------------------------
!onerror tryNoFlow
!flow hardware
!baud 115200
;Send the acknowledge request to the driver (also sends an extra linefeed -- oh well)
~@@
;See if the driver is already running (if not it will throw an error)
!expect hi
'Driver already running, exiting init script now
!goto END
;----- Same but with no flow control enabled (for //c support)
:tryNoFlow
!onerror try19200
!flow none
!baud 115200
~@
;See if the driver is already running (if not it will throw an error)
!expect hi
'Driver already running, exiting init script now
!goto END
;-----------------------------------------------------------------
; Try 19200 baud with Hardware flow control -- this is compatible with a SSC
:try19200
'Trying 19200 baud
!onerror try300
; (for //e,//gs use HARDWARE, for //C use NONE)
!flow HARDWARE
!baud 19200
~PR#2
]
!goto INIT
;-----------------------------------------------------------------
; Try 300 baud with no flow control -- this is compatible with //c
:try300
'Trying 300 baud
!onerror INIT_ERROR
!flow NONE
!baud 300 
;If it is operating at 300 baud, it is probably a //c -- set flow control to NONE
;This first line makes the apple echo input
~PR#2
]
!goto INIT
;-----------------------------------------------------------------
;Now we know the current apple speed, kick it into overdrive (115.2k baud)
:INIT
!onerror INIT2_ERROR
*home:call -151
"Changing port speed
;This binary code kicks the SSC into 115.2k baud, 8-N-1
*300:a9 10 8d ab c0 a9 0b 8d aa c0 ad a8 c0 60
;Start the program to reset the port speed
300g
;Extra linefeed just in case!
~
;Give the apple a moment to catch up
!wait 250
;Now change our speed to match the apple's
!baud 115200
;Expect a valid monitor prompt before going on!
*
;-----------------------------------------------------------------
;This part loads the SOS driver to the apple's ram by typing it in one byte at a time
:LOAD_DRIVER
!onerror DRIVER_ERROR
'Sending driver
"Loading driver     
;type in the program now.
!typeHex /data/sos#060800 800
;Now execute the driver.  Note: The first byte at $800 is unused.
801g
!goto END
;-----------------------------------------------------------------
:INIT_ERROR
!error "Could not figure out what baud rate the apple is using!  Make sure its port settings are No partity, 8 data bits and 1 stop bit (N-8-1).  For a SSC, set the default baud rate to 19200.  For a //c, leave the port at 300 baud."
!goto END
;-----------------------------------------------------------------
:INIT_ERROR2
!error "Could determine the baud rate, but was unable to set the baud rate on the apple to 115.2k baud."
!goto END
;-----------------------------------------------------------------
:DRIVER_ERROR
!error "Was not able to load driver due to unrecoverable communication errors."
!goto END
;-----------------------------------------------------------------
:END